﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Beeldbankmvc.Models;
using System.Text;

namespace Beeldbankmvc.Helpers
{
    public class Stars
    {
        public static String render(int mediaObjectId)
        {
            StarRatingRepository StarRatingRep = new StarRatingRepository();
            StarRatingModel starRating = StarRatingRep.FindOne(mediaObjectId);

            String[] keuzes = { "1 Ster", "2 Sterren", "3 Sterren", "4 Sterren", "5 Sterren" };


            StringBuilder retString = new StringBuilder();

            retString.AppendLine("<!-- star rating -->");
            retString.AppendLine("<div class=\"ratings\">");
            retString.AppendLine("  <div class=\"rating-L\">");
            retString.AppendLine("      <strong id=\"rating_title\">Beoordeel: </strong>");
            retString.AppendLine("      <form id=\"rat\" action=\"/Home/Rate\" method=\"post\">");
            retString.AppendLine("      <fieldset>");
            retString.AppendLine("              <select name=\"rate\">");
            for(int i=0; i< keuzes.Length; i++ )
            {
                String tmp = "<option value=\"" + (i+1) + "\"";
                if ((i+1) == Convert.ToInt32(starRating.avg))
                {
                    tmp += " selected=\"selected\">";
                }
                else
                {
                    tmp += ">";
                }
                tmp += keuzes[i] + "</option>";
                retString.AppendLine(tmp);
            }
            retString.AppendLine("              </select>");
            retString.AppendLine("          <input type=\"hidden\" value=\"" + mediaObjectId + "\" id=\"mediaObjectId\" name=\"mediaObjectId\" />");
            retString.AppendLine("          <input type=\"submit\" value=\"Stem\" />");
            retString.AppendLine("       </fieldset>");
            retString.AppendLine("       </form>");
            retString.AppendLine("  </div>");
            retString.AppendLine("</div>");
            retString.AppendLine("<!-- end star rating -->");

            return retString.ToString();
        }
    }
}